[Repo Assist] Fix custom attribute encoding for generative type providers#463
Draft
github-actions[bot] wants to merge 2 commits intomasterfrom
Draft
[Repo Assist] Fix custom attribute encoding for generative type providers#463github-actions[bot] wants to merge 2 commits intomasterfrom
github-actions[bot] wants to merge 2 commits intomasterfrom
Conversation
…sValue to all attribute args - Implement encodeCustomAttrElemTypeForObject for obj[] — previously threw 'TODO: can't yet emit arrays in attrs'. Now infers element type from the runtime array type and encodes SZARRAY + element type byte per ECMA-335. - Apply transValue to constructorArgs and named property/field values in defineCustomAttrs. Previously transValue was defined but never called, meaning System.Type values in attribute constructor arguments were not translated to their target ILType — potentially encoding design-time type names instead of target names. Tests: 104 passed, 0 failed Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Feb 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Two related fixes to custom attribute encoding in the generative type provider assembly compiler (
AssemblyCompiler/defineCustomAttrs).Fix 1: Implement array support in
encodeCustomAttrElemTypeForObjectBefore: Passing an
obj[](or typed array likestring[]) as an argument to anObject-typed custom attribute constructor parameter would throw:After: Infers the element type from the runtime array type and encodes
SZARRAY + element type byteper ECMA-335 §II.23.3. Supported element types:string,bool,char,sbyte/byte,int16/uint16,int32/uint32,int64/uint64,single,double, andobj(encoded asOBJECT).Fix 2: Apply
transValueto all custom attribute argument valuesBefore:
transValue(which translatesSystem.Type→ILType) was defined insidedefineCustomAttrsbut never used — the function was dead code. Constructor arguments and named properties/fields were passed through untranslated.After:
transValueis moved before its first use and applied to:constructorArgs)namedProps)namedFields)This ensures that if a custom attribute argument contains a
System.Typevalue (e.g.,typeof(SomeProvidedType)), it is translated to the targetILTypeand the correct type name is encoded in the binary attribute blob.Root cause
Both issues affect generative type providers only. Erased providers reflect attributes directly without going through ECMA-335 binary encoding.
Test Status
All existing tests pass: 104 passed, 0 failed on net8.0.
Note: the new functionality (array args, Type args in attrs) is exercised by the fixes themselves but no dedicated integration test is added — adding one would require a new generative provider test fixture with attributes using these specific parameter patterns.